package net.daum.codegen.domain;

public class Column extends BaseObject {
	private static final long serialVersionUID = 4496109592348127180L;
	private String name;
	private String type;
	private String constraintName;
	private String extra;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}	
	public String getConstraintName() {
		return constraintName;
	}
	public void setConstraintName(String constraintName) {
		this.constraintName = constraintName;
	}
	public String getExtra() {
		return extra;
	}
	public void setExtra(String extra) {
		this.extra = extra;
	}	
	public String getJavaType() {
		if ("varchar".equals(type)) {
			return "String";
		}
		
		if ("int".equals(type)) {
			return "Long";
		}
		
		if ("tinyint".equals(type)) {
			return "Boolean";
		}
		
		if ("timestamp".equals(type)) {
			return "Date";
		}
		
		if ("datetime".equals(type)) {
			return "Date";
		}
		
		return "String";
	}
	
	public boolean isSystemColumn() {
		if ("auto_increment".equals(this.extra)) {
			return true;
		}
		
		if ("timestamp".equals(this.type)) {
			return true;
		}
		
		return false;
	}
	
	public boolean isPrimary() {
		return "PRIMARY".equals(this.constraintName);
	}	
}